from apps.address.models import Address
from django.core.cache import cache

class AddressService:
    @classmethod
    def get_user_addresses(cls, user_id):
        cache_key = f'user_{user_id}_addresses'
        addresses = cache.get(cache_key)
        if not addresses:
            addresses = list(Address.objects.filter(user_id=user_id).values())
            cache.set(cache_key, addresses, timeout=300)  # 5分钟缓存
        return addresses

